<!DOCTYPE html>
<html lang="en">
    <head>
        <meta charset="UTF-8">
        <title>流程控制</title>
    </head>
    <body>
        <script>
            // 1.顺序结构
            console.log('1');
            console.log('2');
            console.log('3');
            // 2.分支结构
            let username = 'tom';
            // 若用户名是空串‘’转为布尔是false，！false为true，会走分支1
            if (!username) {
                alert('用户名不能为空')
            }else {
                alert('欢迎'+username+'回归！')
            }
            //3.选择分支
            let gender = 10;
            switch (gender) {
                case 1:
                    console.log('男');
                    break;
                case 0:
                    console.log('女');
                    break;
                default:
                    console.log('人妖');
            }
            // 4.循环结构
            let names = ['tom','jerry','lucy','lili'];
            for (let i = 0; i < names.length; i++) {
                console.log(names[i]);
            }
            //如果用var定义循环变量i，循环结束后在此处仍能打印出i的值
            //但如果用let定义，就会报错：变量i不存在！
            console.log(i);

            //增强for循环
            for (let item of names) {
                console.log(item);
            }
        </script>
    </body>
</html>